package com.algorithm;

/**
 * @author: sun.hongliang
 * @create: 2019/12/02 14:13
 */
public class CanJumpTest {
    public static void main(String[] args) {

    }

    public boolean canJump(int[] nums) {
        return canJumpEnd(0, nums);
    }

    public boolean canJumpEnd(int index, int[] nums) {
        int lastIndex = nums.length - 1;
        if (index == lastIndex) {
            return true;
        }
        int jumpMaxIndex = Math.min(nums[index] + index, lastIndex);
        for (int i = index + 1; i <= jumpMaxIndex; i++) {
            if (canJumpEnd(i, nums)) {
                return true;
            }
        }
        return false;
    }
}
